package com.uphone.kingmall.activity.personal.set;

import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;

import com.china.zhuoyue.R;
import com.lzy.okgo.model.HttpParams;
import com.uphone.kingmall.base.BaseActivity;
import com.uphone.kingmall.utils.CommonUtil;
import com.uphone.kingmall.utils.HttpParamsUtils;
import com.uphone.kingmall.utils.MyUrl;
import com.uphone.kingmall.utils.StringUtils;
import com.uphone.kingmall.view.SubmitButton;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * <pre>
 *     author : 王雨
 *     e-mail : sunzengyan@outlook.com
 *     time   : 2018/07/31
 *     desc   :修改登录密码
 *     version: 1.0
 * </pre>
 */
public class ModifyLoginPwdActivty extends BaseActivity {
    @BindView(R.id.iv_back)
    ImageView ivBack;
    @BindView(R.id.et_pwd_old)
    EditText etPwdOld;
    @BindView(R.id.et_pwd_new)
    EditText etPwdNew;
    @BindView(R.id.et_pwd_confirm)
    EditText etPwdConfirm;
    @BindView(R.id.btn_quren)
    SubmitButton btnQuren;

    @Override
    public int getLayoutContentId() {
        return R.layout.kingmall_activity_modify_login_pwd;
    }

    @Override
    public void initView() {
        setStatusBar();
        btnQuren.setRelaViews(etPwdOld, etPwdNew, etPwdConfirm);
    }

    @Override
    public void initData() {

    }


    @OnClick({R.id.iv_back, R.id.btn_quren})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_back:
                finish();
                break;
            case R.id.btn_quren:
                if (TextUtils.isEmpty(etPwdOld.getText().toString()) || TextUtils.isEmpty(etPwdNew.getText().toString())
                        || TextUtils.isEmpty(etPwdConfirm.getText().toString())) {
                    showShortToast("请将数据填写完整");
                    return;
                }
                if (etPwdNew.getText().toString().trim().length() < 6 || etPwdNew.getText().toString().trim().length() > 20) {
                    showShortToast("请将密码限制在6-20位之间");
                    return;
                }
                if (!StringUtils.isLetterDigit(etPwdNew.getText().toString().trim())) {
                    showShortToast("密码格式不正确");
                    return;
                }
                if (!etPwdNew.getText().toString().trim().equals(etPwdConfirm.getText().toString().trim())) {
                    showShortToast("两次密码不一致");
                    return;
                }

                HttpParams params = HttpParamsUtils.getInstance()
                        .put("priPass", etPwdOld.getText().toString().trim())
                        .put("newPass", etPwdNew.getText().toString().trim())
                        .getParams();
                CommonUtil.submitNetAndFinish(this, MyUrl.changeUserPassword, params, "修改密码成功");
                break;
        }
    }
}
